package com.service.report;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Vector;

import com.bpms.common.CommonUtil;
import com.bpms.common.Tools;
import com.bpms.common.VO;
import com.bpms.common.VOList;
import com.bpms.esb.IService;


public class CopyOfHdprintreport implements IService{

	@SuppressWarnings("unchecked")
	public VO exec(VO arg0) {
		VO result = new VO();
		VOList relist = new VOList();
		try{
			VOList list = (VOList) arg0.getObj("volist");
			Vector v = list.listData;
			Iterator it = v.iterator();
			while(it.hasNext()){
				VO vo = (VO)it.next();
				VO temp = new VO();
				String date = vo.getAttr("billDate");
				String yyyy = date.substring(0, 4);
				String mm = date.substring(4, 6);
				String dd = date.substring(6);
				
				temp.setAttr("yyyy", yyyy);
				temp.setAttr("mm", mm);
				temp.setAttr("dd", dd);
				temp.setAttr("CQC", vo.getAttr("payerName"));
				temp.setAttr("SQC", vo.getAttr("payeeName"));
				temp.setAttr("CZH", vo.getAttr("accNo"));
				temp.setAttr("SZH", vo.getAttr("otherAcc"));
				temp.setAttr("CKHYH", vo.getAttr("sendBankNo"));
				temp.setAttr("SKHYH", vo.getAttr("recBankNo"));
				String money = vo.getAttr("accAmt");
				temp.setAttr("JE",Tools.numtochinese(money));
				String[] attr = toNum(money);
				
				temp.setAttr("F", attr[1]);
				temp.setAttr("J", attr[2]);
				temp.setAttr("Y", attr[4]);
				temp.setAttr("S", attr[5]);
				temp.setAttr("B", attr[6]);
				temp.setAttr("Q", attr[7]);
				temp.setAttr("W", attr[8]);
				temp.setAttr("SW", attr[9]);
				temp.setAttr("BW", attr[10]);
				temp.setAttr("QW", attr[11]);
				temp.setAttr("Yi", attr[12]);
				
				temp.setAttr("PJZL", vo.getAttr("bsnTyp"));
				temp.setAttr("PJHM", vo.getAttr("billNo"));
				temp.setAttr("PJZS", "1");
				temp.setAttr("FHJZ", " ");
				temp.setAttr("FH", " " );
				temp.setAttr("JZ", " ");
				temp.setAttr("KHYHQZ", " ");
				
				relist.listData.add(temp);
			}
			result.setObj("list", relist);
		}catch(Exception e){
			CommonUtil.debug("HdPrintReport exception");
		}
		return result;
	}

	String[] toNum(String str){
		String s = "";
		String[] attr = new String[]{};
		for(int i = str.length(); i>=0 ;i--){
			if(i+1>str.length()){
				s = str.substring(i);
			}else{
				s = str.substring(i, i+1);
			}
			//attr = Arrays.copyOf(attr, attr.length + 1);
			attr[attr.length-1] = s;
		}
		//attr = Arrays.copyOf(attr, attr.length + 1);
		attr[attr.length-1] = "￥";
		int len = attr.length;
		if(len<15){
			for(int j = len;j<=15;j++){
				//attr = Arrays.copyOf(attr, attr.length + 1);
				attr[j] = " ";
			}
		}
		return attr;
	}
	
//	public static String code2code(String strIn, String sourceCode,
//			String targetCode) {
//		String strOut = null;
//		if (strIn == null || (strIn.trim()).equals(""))
//			return strIn;
//		try {
//			byte[] b = strIn.getBytes(sourceCode);
//			for (int i = 0; i < b.length; i++) {
//			}
//			strOut = new String(b, targetCode);
//		} catch (Exception e) {
//			CommonUtil.debug("HdPrintReport code2code error");
//			return null;
//		}
//		return strOut;
//	}
	
}
